import React, { Component } from 'react'
import { addNavigationHelpers } from 'react-navigation'
import { connect } from 'react-redux'
import PropTypes from 'prop-types'
import AppNavigator from './index'

class AppWithNavigationState extends Component {
  static propTypes = {
    dispatch: PropTypes.func.isRequired,
    nav: PropTypes.object.isRequired
  }

  render() {
    const { dispatch, nav } = this.props
    // console.log('dispatch', this.props)
    return (
        <AppNavigator
          navigation={addNavigationHelpers({
            dispatch,
            state: nav
          })}
        />
    )
  }
}

const mapStateToProps = state => ({
  nav: state.nav
})

export default connect(mapStateToProps)(AppWithNavigationState)
